package com.rd.student.dashuju.zhengruixian.kaoshi0808;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) throws IOException {
        ArrayList<Student1> list=new ArrayList<Student1>();
        addStudent1(list);
        addStudent2(list);
        addStudent3(list);
        BufferedWriter bw=new BufferedWriter(
                new FileWriter("Student.txt"));
        bw.write("姓名  语文成绩  数学成绩  总成绩");
        bw.newLine();
        for (int i = 0; i < list.size(); i++) {
            bw.write(list.toString());
            bw.newLine();
        }
        bw.close();
    }
    public static void addStudent1(ArrayList<Student1> list){
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入学生姓名:");
        String name=scanner.nextLine();
        System.out.println("请输入学生的语文成绩:");
        int ygrade=scanner.nextInt();
        System.out.println("请输入学生的数学成绩:");
        int sgrade=scanner.nextInt();
        int sum=ygrade+sgrade;
        Student1 student1=new Student1();
        student1.setName(name);
        student1.setYgrade(ygrade);
        student1.setSgrade(sgrade);
        student1.setSum(sum);
        list.add(student1);
    }
    public static void addStudent2(ArrayList<Student1> list){
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入学生姓名:");
        String name=scanner.nextLine();
        System.out.println("请输入学生的语文成绩:");
        int ygrade=scanner.nextInt();
        System.out.println("请输入学生的数学成绩:");
        int sgrade=scanner.nextInt();
        int sum=ygrade+sgrade;
        Student1 student2=new Student1();
        student2.setName(name);
        student2.setYgrade(ygrade);
        student2.setSgrade(sgrade);
        student2.setSum(sum);
        list.add(student2);
    }
    public static void addStudent3(ArrayList<Student1> list) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入学生姓名:");
        String name=scanner.nextLine();
        System.out.println("请输入学生的语文成绩:");
        int ygrade=scanner.nextInt();
        System.out.println("请输入学生的数学成绩:");
        int sgrade=scanner.nextInt();
        int sum=ygrade+sgrade;
        Student1 student3=new Student1();
        student3.setName(name);
        student3.setYgrade(ygrade);
        student3.setSgrade(sgrade);
        student3.setSum(sum);
        list.add(student3);

    }

}
